package com.zhongbei.controller;

import com.zhongbei.pojo.Record;
import com.zhongbei.service.RecordService;
import com.zhongbei.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/record")
public class RecordController {

    @Autowired
    private RecordService recordService;

    @PostMapping
    public Result<String> create(@RequestBody Record record) {
        int i = recordService.insertSelective(record);
        return i == 1 ? Result.success("新增成功") : Result.error("新增失败");
    }

    @DeleteMapping("/{feeId}")
    public Result<String> delete(@PathVariable Integer feeId) {
        int i = recordService.deleteByfeeId(feeId);
        return i == 1 ? Result.success("删除成功") : Result.error("删除失败");
    }

    @PutMapping("/{feeId}")
    public Result<String> update(@PathVariable Integer feeId, @RequestBody Record record) {
        record.setFeeId(feeId);
        int i = recordService.updateByfeeId(record);
        return i == 1 ? Result.success("修改成功") : Result.error("修改失败");
    }

    @GetMapping("/{feeId}")
    public Result<Record> getById(@PathVariable Integer feeId) {
        return Result.success(recordService.selectByfeeId(feeId));
    }
}
